﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.tools
{
    /// <summary>
    /// get_city 的摘要说明
    /// </summary>
    public class get_city : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //取得处事类型
            string action = DTRequest.GetQueryString("action");

            switch (action)
            {
                case "get_citys": //调用城市
                    get_citys(context);
                    break;
                case "get_area": //调用地区
                    get_area(context);
                    break;
            }
        }

        #region 获取城市=====================================
        private void get_citys(HttpContext context)
        {
            int province_id = DTRequest.GetFormInt("province_id");

            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("<option value=\"0\">请选择您所在城市</option>\n");
            BLL.city bll = new BLL.city();
            DataSet ds = bll.GetList(0, "province_id=" + province_id, "id asc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("<option value=\"" + dr["id"].ToString() + "\">" + dr["city_name"].ToString() + "</option>\n");
                }
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 获取地区=====================================
        private void get_area(HttpContext context)
        {
            int city_id = DTRequest.GetFormInt("city_id");

            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("<option value=\"0\">请选择您所在地区</option>\n");
            BLL.district bll = new BLL.district();
            DataSet ds = bll.GetList(0, "city_id=" + city_id, "id asc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("<option value=\"" + dr["id"].ToString() + "\">" + dr["district_name"].ToString() + "</option>\n");
                }
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}